﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Collections;


public partial class about : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {

        ArrayList alAbout = new ArrayList(ConfigurationManager.AppSettings["About"].Split(';'));
        bool bCanSeeAboutTabs = true;// alAbout.Contains(((((System.Web.UI.Page)(this)).User).Identity).Name);
        TabContainer1.Style["display"] = bCanSeeAboutTabs ? "" : "none";

        Application["Application Start"] = Application["Application Start"] == null ? "Not Set" : Application["Application Start"];
        Application["Application End"] = Application["Application End"] == null ? "Not Set" : Application["Application End"];

        Application["Session Start"] = Application["Session Start"] == null ? "Not Set" : Application["Session Start"];
        Application["Session End"] = Application["Session End"] == null ? "Not Set" : Application["Session End"];
        Application["ACC_DATA Cached On"] = Application["ACC_DATA Cached On"] == null ? "Not Set" : Application["ACC_DATA Cached On"];
        Application["ACC_DATA Sizes"] = Application["ACC_DATA Sizes"] == null ? "Not Set" : Application["ACC_DATA Sizes"];
        Application["ACC_DATA Times"] = Application["ACC_DATA Times"] == null ? "Not Set" : Application["ACC_DATA Times"];

        Application["ACC_PROPERTIES Cached On"] = Application["ACC_PROPERTIES Cached On"] == null ? "Not Set" : Application["ACC_PROPERTIES Cached On"];
        Application["ACC_PROPERTIES Sizes"] = Application["ACC_PROPERTIES Sizes"] == null ? "Not Set" : Application["ACC_PROPERTIES Sizes"];
        Application["ACC_PROPERTIES Times"] = Application["ACC_PROPERTIES Times"] == null ? "Not Set" : Application["ACC_PROPERTIES Times"];

        Application["ACC_STATES Cached On"] = Application["ACC_STATES Cached On"] == null ? "Not Set" : Application["ACC_STATES Cache On"];

        Application["ACC_STATS_YR_MN Cached On"] = Application["ACC_STATS_YR_MN Cached On"] == null ? "Not Set" : Application["ACC_STATS_YR_MN Cache On"];
        Application["ACC_STATS_YR_MN Sizes"] = Application["ACC_STATS_YR_MN Sizes"] == null ? "Not Set" : Application["ACC_STATS_YR_MN Sizes"];
        Application["ACC_STATS_YR_MN Times"] = Application["ACC_STATS_YR_MN Times"] == null ? "Not Set" : Application["ACC_STATS_YR_MN Times"];

        Application["ACC_STATS_YR_MN_DY Cached On"] = Application["ACC_STATS_YR_MN_DY Cached On"] == null ? "Not Set" : Application["ACC_STATS_YR_MN_DY Cache On"];
        Application["ACC_STATS_YR_MN_DY Sizes"] = Application["ACC_STATS_YR_MN_DY Sizes"] == null ? "Not Set" : Application["ACC_STATS_YR_MN_DY Sizes"];
        Application["ACC_STATS_YR_MN_DY Times"] = Application["ACC_STATS_YR_MN_DY Times"] == null ? "Not Set" : Application["ACC_STATS_YR_MN_DY Times"];
    }

    protected string ACC_DATASize()
    {
        DataSet ds = (DataSet)Cache["ACC_DATA"];
        if (ds != null)
            return (ds.Tables[0].Rows.Count + ds.Tables[1].Rows.Count + ds.Tables[2].Rows.Count + ds.Tables[3].Rows.Count).ToString();
        else
            return "0";

    }

    protected void ddlCacheName_SelectedIndexChanged(object sender, EventArgs e)
    {
        Cachola dCache = new Cachola(ddlCacheName.SelectedItem.Text);
        ddlTableName.Items.Clear();
        ddlTableName.Items.Add("Select a Table");
        lblRows.Text = "";

        ddlTableName.DataSource = dCache.TableNamesList();
        ddlTableName.DataBind();
    }


    protected void ddlTableName_SelectedIndexChanged(object sender, EventArgs e)
    {
        Cachola dCache = new Cachola(ddlCacheName.SelectedItem.Text);
        grvTable.DataSource = dCache.Table(ddlTableName.SelectedItem.Text);
        grvTable.DataBind();

        lblRows.Text = dCache.Table(ddlTableName.SelectedItem.Text).Rows.Count.ToString("###,###");
        dtvRow.DataSource = dCache.Table(ddlTableName.SelectedItem.Text);
        dtvRow.DataBind();
    }
    protected void ddlColumnName_SelectedIndexChanged(object sender, EventArgs e)
    {
        Cachola dCache = new Cachola(ddlCacheName.SelectedItem.Text);
        grvTable.DataSource = dCache.Table(ddlTableName.SelectedItem.Text, ddlColumnName.SelectedItem.Text);

        grvTable.DataBind();

        dtvRow.DataSource = dCache.Table(ddlTableName.SelectedItem.Text);
        dtvRow.DataBind();

    }
    protected void btnRefresh_Click(object sender, EventArgs e)
    {
        System.IO.File.WriteAllText(HttpContext.Current.Server.MapPath("SQL\\Data\\CachedSalesDate.txt"), DateTime.Today.AddMonths(-1).ToString());
        System.IO.File.WriteAllText(HttpContext.Current.Server.MapPath("SQL\\Data\\ServerSalesDate.txt"), DateTime.Today.AddMonths(-2).ToString());
        Restart();
    }

    private void Restart()
    {

        System.Web.HttpRuntime.UnloadAppDomain();
        System.Net.WebClient myWebClient = null;
        try
        {
            string url = Request.UrlReferrer.AbsoluteUri;     
            myWebClient = new System.Net.WebClient();
            byte[] stuff = myWebClient.DownloadData(url);
        }
        catch
        {
        }
        finally
        {
            myWebClient.Dispose();
        }
    }


}